home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / uname.c < prev    next >
C/C++ Source or Header  |  1993-09-15  |  2KB  |  91 lines

  1. /*
  2.  * uname() emulation by Dave Gymer. In the public domain.
  3.  * Bugs:
  4.  *    The MiNT version stuff is in the release field. According to the GNU
  5.  *    shell utils this is the way SunOS does it, so we put the TOS
  6.  *    version number in the 'version' field (even under MiNT).
  7.  *
  8.  * (Modified slightly by ERS.)
  9.  */
  10.  
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13. #include <osbind.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #ifdef __TURBOC__
  17. #include <sys\utsname.h>
  18. #else
  19. #include <sys/utsname.h>
  20. #endif
  21.  
  22. extern int __mint;
  23. __EXTERN int gethostname __PROTO((char *buf, size_t len));
  24.  
  25. static long _mch;    /* value of the _MCH cookie, if any */
  26. static int tosvers;    /* TOS version number */
  27.  
  28. /*
  29.  * get operating system information; must execute in supervisor mode
  30.  */
  31.  
  32. static long getinfo __PROTO((void));
  33.  
  34. static long
  35. getinfo()
  36. {
  37.     long *cookie, *sysbase;
  38.  
  39. /* get _MCH cookie value */
  40.     cookie = *((long **) 0x5a0L);
  41.     if (cookie) {
  42.         while (*cookie) {
  43.             if (*cookie == 0x5f4d4348L) {    /* _MCH */
  44.                 _mch = cookie[1];
  45.                 break;
  46.             }
  47.             cookie += 2;
  48.         }
  49.     }
  50.  
  51. /* get TOS version number */
  52.     sysbase = *((long **)(0x4f2L));
  53.     tosvers = (int)(sysbase[0] & 0x0000ffff);
  54.     return 0;
  55. }
  56.  
  57. #define HILO(x) (int) ((x >> 8) & 255), (int) (x & 255)
  58.  
  59. int
  60. uname(buf)
  61.     struct utsname *buf;
  62. {
  63.     if (!tosvers)
  64.         (void)Supexec(getinfo);
  65.  
  66.     strcpy(buf->sysname, __mint ? "MiNT" : "TOS");
  67.  
  68.     if (gethostname(buf->nodename, (size_t) 15))
  69.         strcpy(buf->nodename, "??node??");
  70.  
  71.     if (__mint)
  72.         sprintf(buf->release, "%d.%d", HILO(__mint));
  73.     else
  74.         buf->release[0] = 0;
  75.  
  76.     sprintf(buf->version, "%d.%d", HILO(tosvers));
  77.  
  78.     switch((int)((_mch >> 16) & 0x0ffffL)) {
  79.     case 0:
  80.         strcpy(buf->machine, "atarist"); break;
  81.     case 1:
  82.         strcpy(buf->machine, "atariste"); break;
  83.     case 2:
  84.         strcpy(buf->machine, "ataritt"); break;
  85.     default:
  86.         strcpy(buf->machine, "atari");
  87.     }
  88.  
  89.     return 0;
  90. }
  91.